dynamic class SoundManager
{
    static var soundDepth: Number = 99999;
    static var soundArr = new Array();
    static var activeSoundArr = new Array();
    static var activeSoundPos = new Array();

    function SoundManager()
    {
        SoundManager.thisRef = this;
    }

    static function setMasterSound(masterTarg)
    {
        SoundManager.masterSound = new Sound(masterTarg);
    }

    static function setMasterVolume(mVol)
    {
        SoundManager.masterSound.setVolume(mVol);
    }

    static function getMasterVolume()
    {
        var __reg1 = SoundManager.masterSound.getVolume();
        return __reg1;
    }

    static function addSound(soundName, soundTarg, soundVol, soundPan)
    {
        ++SoundManager.soundDepth;
        var __reg3 = "sound" + SoundManager.soundDepth;
        soundTarg.createEmptyMovieClip(__reg3, SoundManager.soundDepth);
        var __reg4 = soundTarg[__reg3];
        soundTarg[soundName] = new Sound(__reg4);
        soundTarg[soundName].attachSound(soundName);
        SoundManager.soundArr[soundName] = soundTarg[soundName];
        if (soundVol != undefined) 
        {
            SoundManager.volSet(soundName, soundVol);
            SoundManager.panSet(soundName, soundPan);
        }
    }

    static function addSoundArray(soundArr, soundTarg)
    {
        var __reg1 = 0;
        for (;;) 
        {
            if (__reg1 >= soundArr.length) 
            {
                return;
            }
            SoundManager.addSound(soundArr[__reg1], soundTarg);
            ++__reg1;
        }
    }

    static function startSound(sName, sIn, rNum)
    {
        trace("* startSound (" + sName + ") : " + SoundManager.soundArr[sName] + " : vol : " + SoundManager.volGet(sName));
        if (sIn == undefined) 
        {
            sIn = 0;
        }
        SoundManager.stopSound(sName);
        SoundManager.soundArr[sName].start(sIn, rNum);
        SoundManager.soundArr[sName].loopNum = rNum;
    }

    static function stopSound(sName)
    {
        SoundManager.soundArr[sName].stop();
    }

    static function volSet(sName, volLev)
    {
        SoundManager.soundArr[sName].setVolume(volLev);
    }

    static function volGet(sName)
    {
        return SoundManager.soundArr[sName].getVolume();
    }

    static function panSet(sName, volLev)
    {
        SoundManager.soundArr[sName].setPan(volLev);
    }

    static function panGet(sName)
    {
        return SoundManager.soundArr[sName].getPan();
    }

    static function fadeSound(sName, volLev, intNum)
    {
        trace(sName + " fadeSound -> " + volLev);
        clearInterval(SoundManager.fadeInt);
        SoundManager.fadeInt = setInterval(SoundManager.fadeStep, intNum, sName, volLev);
    }

    static function panSound(sName, panLev, intNum)
    {
        SoundManager.panInt = setInterval(SoundManager.panStep, intNum, sName, panLev);
    }

    static function stopActiveSounds()
    {
        _global.zoomSoundStop = true;
        SoundManager.activeSoundArr = [];
        for (var __reg4 in SoundManager.soundArr) 
        {
            var __reg2 = SoundManager.soundArr[__reg4];
            var __reg3 = __reg2.position;
            if (__reg3 != 0) 
            {
                SoundManager.activeSoundArr.push(__reg2);
                SoundManager.activeSoundPos.push(__reg3);
                __reg2.stop();
            }
        }
    }

    static function startActiveSounds()
    {
        _global.zoomSoundStop = false;
        var __reg4 = 0;
        for (;;) 
        {
            if (__reg4 >= SoundManager.activeSoundArr.length) 
            {
                return;
            }
            var __reg2 = SoundManager.activeSoundArr[__reg4];
            var __reg5 = SoundManager.activeSoundPos[__reg4] / 1000;
            for (var __reg6 in __reg2) 
            {
                if (__reg6 == "loopNum") 
                {
                    var __reg3 = __reg2[__reg6];
                }
            }
            if (__reg3 > 1) 
            {
                __reg2.start(0, __reg3);
            }
            else 
            {
                __reg2.start(__reg5, 1);
            }
            ++__reg4;
        }
    }

    static function fadeStep(sName, volLev)
    {
        var __reg1 = SoundManager.volGet(sName);
        var __reg2 = __reg1;
        if (volLev != __reg1) 
        {
            if (__reg1 < volLev) 
            {
                ++__reg2;
            }
            else 
            {
                --__reg2;
            }
            SoundManager.volSet(sName, __reg2);
            return;
        }
        clearInterval(SoundManager.fadeInt);
    }

    static function panStep(sName, panLev)
    {
        var __reg2 = SoundManager.panGet(sName);
        var __reg1 = __reg2;
        if (panLev != __reg2) 
        {
            if (__reg2 < panLev) 
            {
                ++__reg1;
            }
            else 
            {
                --__reg1;
            }
            SoundManager.panSet(sName, __reg1);
            return;
        }
        clearInterval(SoundManager.panInt);
    }

    static function setOnComplete(sName, cFunc, cScope)
    {
        SoundManager.soundArr[sName].onSoundComplete = function ()
        {
            cFunc.apply(cScope);
        }
        ;
    }

}
